﻿@page "/Wms/BuyInWarehouseDetail/Edit"
@using nERP.ViewModel.Wms.BuyInWarehouseDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.BuyInWarehouseId" Items="AllBuyInWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g17652ac5ae32461e9571c67d0004314e" />
            <BootstrapInput @bind-Value="@Model.Entity.BuyInWarehouseDetailCode" />
            <Select @bind-Value="@Model.Entity.WarehouseId" Items="AllWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g422fac87e8db416e86a3ba4d78b41a84" />
            <Select @bind-Value="@Model.Entity.BuyId" Items="AllBuys" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gc81764efb40348c0a4ddb63bf2450cf7" />
            <Select @bind-Value="@Model.Entity.BuyDetailId" Items="AllBuyDetails" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g1654a9ee8f734a42843a7e24278ee69f" />
            <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g7c4c4174f4ee43ed87c96448e3e11fa7" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsName" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit" />
            <BootstrapInput @bind-Value="@Model.Entity.BuyInNumber" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyInWarehouseDetailVM Model = new BuyInWarehouseDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Wms/BuyInWarehouseDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllBuyInWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllBuyDetails = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllBuyInWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouseDetail/GetBuyInWarehouses");
        AllBuyInWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouseDetail/GetWarehouses");
        AllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouseDetail/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllBuyDetails = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouseDetail/GetBuyDetails");
        AllBuyDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouseDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<BuyInWarehouseDetailVM>($"/api/Wms/BuyInWarehouseDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
